package dhee.wtqshopproject.dao;

import dhee.wtqshopproject.entity.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface ProductIndexMapper {
    // 根据分类ID分页查询前40个展示商品
    @SelectProvider(type = ProductSqlProvider.class, method = "selectByCategoryWithLimit")
    List<Product> selectByCategoryWithLimit(@Param("categoryId") Integer categoryId,@Param("offset") int offset);

    // 查询每个分类前6个商品
    @SelectProvider(type = ProductSqlProvider.class, method = "selectByCategoriesWithLimit")
    List<Product>selectByCategoriesWithLimit();
    // 商品搜索（名称或描述模糊查询）
    @Select("SELECT * FROM product WHERE is_show = 1 AND (name LIKE CONCAT('%', #{keyword}, '%') OR description LIKE CONCAT('%', #{keyword}, '%'))")
    List<Product> searchProducts(String keyword);

    // 商品详情查询
    @Select("SELECT * FROM product WHERE product_id = #{productId}")
    Product selectProductById(Integer productId);
}
